package jianzhiOffer;

import java.util.HashSet;
import java.util.Set;

public class Num38 {
    boolean[] isuse = new boolean[8];
    Set<String> res = new HashSet<>();
    public String[] permutation(String s) {
        int len = s.length();
        char[] chars = s.toCharArray();
        dfs(chars,len,0,"");
        int si = res.size();
        String[] st = new String[si];
        int index = 0;
        for(String str1 : res) {
            st[index++] = str1;
        }
        return st;
    }
    void dfs(char[] chars,int len,int depth,String str) {
        if(depth == len) {
            res.add(str);
            return;
        }
        for(int i = 0; i < len; i++) {
            if(!isuse[i]) {
                isuse[i] = true;
                dfs(chars,len,depth + 1,str + chars[i]);
                isuse[i] = false;
            }
        }
    }
}
